window.onload = function (){
    document.getElementById("productName").onblur = findProductName;
}

var showError = document.getElementById("productNameFind-Error");
var showRight = document.getElementById("productNameFind-Right");
function findProductName() {
    // alert("123");
    //1.创建异步请求对象
    var xmlHttp = new XMLHttpRequest();
    //3.初始化异步请求对象
    var param = document.getElementById("productName").value;
    var flagParam = "";
    if (param == flagParam){
        showError.style.display="block";
        showRight.style.display="none";
        showError.innerText="商品名称不能为空！";
        return false;
    }
    xmlHttp.open("get","/admin/saveProduct_FindName?productName="+param,true);
    //4.发送
    xmlHttp.send();
    //2.为异步请求绑定上事件
    xmlHttp.onreadystatechange = function (){
        if (xmlHttp.readyState==4 && xmlHttp.status==200){
            var data = xmlHttp.responseText;
            proNameCallBack(data);
        }
    };
}
//局部刷新函数
function proNameCallBack(param) {
    if (param==0){
        //代表还没有用户
        showRight.style.display="block";
        showError.style.display="none";
    }else {
        //代表已经有用户
        showRight.style.display="none";
        showError.style.display="block";
        showError.innerText="商品名称已经存在，请更改！";
    }
}